package com.jmemoir.weixin.mp.controller;

import com.jmemoir.common.dto.Result;
import com.jmemoir.weixin.mp.service.WeiXinMpService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 微信公众号控制层
 *
 * @author Tellsea
 * @date 2023/8/15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/weiXinMp")
public class WeiXinMpController {

    private final WeiXinMpService weiXinMpService;

    /**
     * 获取授权登录Url
     *
     * @return
     */
    @GetMapping("getLoginUrl")
    public Result<String> getLoginUrl() {
        return Result.success("操作成功", weiXinMpService.getLoginUrl());
    }

    /**
     * 登录回调
     */
    @RequestMapping("callback")
    public void callback(HttpServletRequest request, HttpServletResponse response) {
        weiXinMpService.callback(request, response);
    }
}
